package com.ai.nsa.actions;

import com.asiainfo.appserver.Action;
import com.asiainfo.appserver.Request;
import com.asiainfo.appserver.Response;
import com.asiainfo.appserver.annotations.Function;
import com.asiainfo.appserver.annotations.Parameter;
import com.asiainfo.appserver.annotations.Type;
import com.asiainfo.its.ITSPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Feng Chen 2017/6/6.
 */
@Function(description = "日志录入", parameters = {
        @Parameter(name = "EVENT", type = Type.String, description = "日志", required = true)
})
@Component
public class NSAIns implements Action {

    @Autowired
    private ITSPool nsaPool;

    private final static Logger logger = LoggerFactory.getLogger(NSAIns.class);

    public Response execute(Request request) throws Exception {
        try {
            String event = request.getString("EVENT");
            nsaPool.emit(event);
            return Response.success();
        } catch (Exception e) {
            logger.error("", e);
            return Response.fail(e);
        }

    }

}